<%
On Error Resume Next

Dim MHEMail
MHEMail = "Morus <morus@jebsen.com>"

Function SendMail (EmailTo, EmailFrom, CcTo, BCcTo, Subject, Body)	
	Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
	Const cdoSendUsingPort = 2
	Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
	Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
	Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
	Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
	Const cdoBasic = 1
	Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
	Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
	
	Dim objConfig  ' As CDO.Configuration
	Dim objMessage ' As CDO.Message
	Dim Fields     ' As ADODB.Fields
	
	' Get a handle on the config object and it's fields
	Set objConfig = Server.CreateObject("CDO.Configuration")
	Set Fields = objConfig.Fields
	
	' Set config fields we care about
	With Fields
		.Item(cdoSendUsingMethod)       = cdoSendUsingPort
		.Item(cdoSMTPServer)            = "JLNDHK01"
		.Item(cdoSMTPServerPort)        = 25
		.Item(cdoSMTPConnectionTimeout) = 10
		.Item(cdoSMTPAuthenticate)      = cdoBasic
		'.Item(cdoSendUserName)          = "username"
		'.Item(cdoSendPassword)          = "password"
	
		.Update
	End With
	
	Set objMessage = Server.CreateObject("CDO.Message")
	
	Set objMessage.Configuration = objConfig
	
	With objMessage
		.To       = EmailTo		
		.From     = EmailFrom
		.Subject  = Subject
        .HTMLBody = Body
        
        If CcTo <> "" Then	.Cc = CcTo
        If BCcTo <> "" Then	.Bcc = BCcTo
		
		.Send
	End With
	
	Set Fields = Nothing
	Set objMessage = Nothing
	Set objConfig = Nothing
	
End Function

'testing
'SendMail "Victor Tai", "victortai@goatstudio.com", "Victor Tai", "victor_tai@jjsea.com", "", "Welcome to Morus", "body: testing cdo <b>ABC</b>"

%>

<%

  Dim MailBody

		Set rs = Server.CreateObject("ADODB.Recordset")
		rs.ActiveConnection = "DSN=morus;UID=sa;PWD=litestep;"
		rs.Source = "SELECT (user_firstname + ' ' + user_midname + ' ' + user_lastname) AS DisplayName, user_mailid, user_password, user_email FROM master_users WHERE user_isad = 0 AND user_password IS NOT NULL"
		rs.CursorType = 0
		rs.CursorLocation = 2
		rs.LockType = 1
		rs.Open()		
		
        If Not rs.EOF Then		
        
            While Not rs.EOF
		
                MailBody = ""
  
                DisplayName = rs("DisplayName")
                LoginName = rs("user_mailid")
                Password = rs("user_password")
                Email = rs("user_email")
  
                MailBody = MailBody & "<p>Dear " & DisplayName & ",</p>"
                MailBody = MailBody & "<p>We are excited to introduce you to Morus, the Jebsen Group's new Intranet service."
                MailBody = MailBody & "<br>This is your one-stop site for the latest corporate news and information."
                MailBody = MailBody & "<br>You can access Morus at <a href='http://morus.jebsen.com/' target='new'>morus.jebsen.com</a> anywhere, even outside the office.</p>"
                MailBody = MailBody & "<br>Below is your temporary login information.</p>"
                MailBody = MailBody & "<p>Username:[" & LoginName & "]"
                MailBody = MailBody & "<br>Password:[" & Password & "]</p>"
                MailBody = MailBody & "<p>&nbsp;</p>"
                MailBody = MailBody & "<p>For security reasons, you are encouraged to change your password under My Profile -> Edit Options.</p>"
                MailBody = MailBody & "<p>We wish you a pleasant experience with Morus.</p>"
                MailBody = MailBody & "<p>Morus Team</p>"
                MailBody = MailBody & "<p><font face='arial' color='#ff0000' size=1>*** This is a system-generated message. Please do not reply to this email. ***</font></p>"

                MailBody = MailBody & "<p>&nbsp;</p>"
                MailBody = MailBody & "<p><hr></p>"
                MailBody = MailBody & "<p>&nbsp;</p>"

                MailBody = MailBody & "<p>亲爱的 " & DisplayName & "</p>"
                MailBody = MailBody & "<p>我们很高兴为你介绍 Morus,捷成集团的新内联网服务。 "
                MailBody = MailBody & "<br>这是你的一站式网站,包含了公司最新的新闻和信息。 "
                MailBody = MailBody & "<br>你可以在任何地点,甚至在办公室以外,通过 <a href='http://morus.jebsen.com/' target='new'>morus.jebsen.com</a> 浏览。 </p>"
                MailBody = MailBody & "<br>以下是你的临时登录信息。 </p>"
                MailBody = MailBody & "<p>用户名: [" & LoginName & "]"
                MailBody = MailBody & "<br>密码: [" & Password & "]</p>"
                MailBody = MailBody & "<p>&nbsp;</p>"
                MailBody = MailBody & "<p>为了安全起见,我们建议你进入我的档案-> 编辑选项,随时更改密码。 更详细的相关资料登录后供你查阅。 </p>"
                MailBody = MailBody & "<p>我们希望你有一个愉快的 Morus 体验。 </p>"
                MailBody = MailBody & "<p>Morus小组</p>"
                MailBody = MailBody & "<p><font face='arial' color='#ff0000' size=1>*** 这是一个由系统自动发送的邮件,请不要回复。 ***</font></p>"

                Response.Write MailBody
                Response.Write "<p>&nbsp</p>"
  
                'SendMail "darrenhow@jebsen.com", "morus@jebsen.com", "", "", "Welcome to Morus", MailBody
                
                rs.MoveNext
            Wend
        End If     
        
        rs.Close
        Set rs = Nothing       

%>